package com.xiongwei.manageback.service.impl;

import cn.hutool.core.util.BooleanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiongwei.manageback.domain.SysFile;
import com.xiongwei.manageback.exception.ServiceException;
import com.xiongwei.manageback.service.SysFileService;
import com.xiongwei.manageback.mapper.SysFileMapper;
import com.xiongwei.manageback.utils.AjaxResult;
import org.springframework.stereotype.Service;

/**
* @author a
* @description 针对表【sys_file(文件上传表)】的数据库操作Service实现
* @createDate 2023-11-01 13:33:16
*/
@Service
public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile>
    implements SysFileService{

    @Override
    public AjaxResult enable(Boolean enable, Integer id) {
        LambdaUpdateWrapper<SysFile> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(SysFile::getId,id);
        if (BooleanUtil.isFalse(enable)){
//            更改状态为禁用
            wrapper.set(SysFile::getEnable,Boolean.FALSE);
        }else {
//            改为启用
            wrapper.set(SysFile::getEnable,Boolean.TRUE);
        }
        if(update(wrapper)){
            return AjaxResult.success();
        }
        throw new ServiceException(ServiceException.UN_KNOW_ERROR,"状态更新失败");
    }
}




